package com.ruoyi.matrix.util

import java.util.*

/**
 *
 * @Description StateUtils
 * @author Fatmore
 * @since 2022/8/8 22:45
 *
 */
object StateUtils {

    fun shortOf(longState: String?): String {
        if (longState == null || longState == "") {
            return ""
        }

        val result = longState.lowercase(Locale.getDefault()).replace("[^a-z0-9]".toRegex(), "")

        val s = dict[result] ?: return longState.uppercase(Locale.getDefault())
        return s.uppercase(Locale.getDefault())
    }


    val dict = mapOf<String, String>(

        "alabama" to "AL",
        "alaska" to "AK",
        "americansamoa" to "AS",
        "arizona" to "AZ",
        "arkansas" to "AR",
        "california" to "CA",
        "colorado" to "CO",
        "connecticut" to "CT",
        "delaware" to "DE",
        "districtofcolumbia" to "DC",
        "federatedstatedofmicronesia" to "FM",
        "florida" to "FL",
        "georgia" to "GA",
        "guam" to "GU",
        "hawaii" to "HI",
        "idaho" to "ID",
        "illinois" to "IL",
        "indiana" to "IN",
        "iowa" to "IA",
        "kansas" to "KS",
        "kentucky" to "KY",
        "louisiana" to "LA",
        "maine" to "ME",
        "marshallislands" to "MH",
        "maryland" to "MD",
        "massachusetts" to "MA",
        "michigan" to "MI",
        "minnesota" to "MN",
        "mississippi" to "MS",
        "missouri" to "MO",
        "montana" to "MT",
        "nebraska" to "NE",
        "nevada" to "NV",
        "newhampshire" to "NH",
        "newjersey" to "NJ",
        "newmexico" to "NM",
        "newyork" to "NY",
        "northcarolina" to "NC",
        "northdakota" to "ND",
        "northernmarianaislands" to "MP",
        "ohio" to "OH",
        "oklahoma" to "OK",
        "oregon" to "OR",
        "palau" to "PW",
        "pennsylvania" to "PA",
        "puertorico" to "PR",
        "rhodeisland" to "RI",
        "southcarolina" to "SC",
        "southdakota" to "SD",
        "tennessee" to "TN",
        "texas" to "TX",
        "utah" to "UT",
        "vermont" to "VT",
        "virginislands" to "VI",
        "virginia" to "VA",
        "washington" to "WA",
        "westvirginia" to "WV",
        "wisconsin" to "WI",
        "wyoming" to "WY",
        "armedforcesamericas" to "AA",
        "armedforcesafrica" to "AE",
        "armedforcescanada" to "AE",
        "armedforceseurope" to "AE",
        "armedforcesmiddleeast" to "AE",
        "armedforcespacific" to "AP",

        )

}

fun main() {
    println(StateUtils.shortOf("Alabama"))
    println(StateUtils.shortOf("Ala bama"))
    println(StateUtils.shortOf("Ala ;' bama"))
    println(StateUtils.shortOf("Alabamaxx"))
    println(StateUtils.shortOf("ak"))
    println(StateUtils.shortOf("al"))
    println(StateUtils.shortOf("AL"))
    val stateStr = "federated Stated of micronesia"
    println(">>>" + StateUtils.shortOf(stateStr))
}